var limsOutsourceApply = Gikam.getPageObject({

    getEditListColumns: function () {
        return [{
            checkbox: true
        },{
            index: true
        }, this.getBpmnColumn(limsOutsourceApply.workflow.dbTable), {
            field: 'applyCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.APPLYCODE',
            type: 'link',
            width: 140
        }, {
            field: 'outsourcerName',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERNAME',
            // width: 140
        }, {
            field: 'outsourcerCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERCODE',
            width: 140
        }, {
            field: 'remark',
            title: 'T_LIMS_OUTSOURCE_APPLY.REMARK',
            editor: true,
            width: 200
        }, {
            field: 'createdByName',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDBYNAME',
            width: 140
        }, {
            field: 'createdTime',
            type: 'dateTime',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDTIME',
            width: 150
        }]
    },

    getBaseInfoFormFields: function () {
        return [{
            field: 'outsourcerCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERCODE',
            validators: ['strLength[0,32]', 'notEmpty'],
            type: 'choose',
            category: 'outsourcer',
            cleanable: false,
            single: true,
            onBeforeChoose: function () {
                return {
                    activedFlag_EQ: '1',
                }
            },
            onAfterChoose: function (rows, index) {
                if (rows) {
                    this.setData({
                        outsourcerId: rows[0].id,
                        outsourcerName: rows[0].outsourcerName,
                        outsourcerCode: rows[0].outsourcerCode
                    })
                }
            },
            preInsert: true,
        }, {
            field: 'outsourcerName',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERNAME',
            editable: false,
            readonly: true,
            validators: ['strLength[0,120]', 'notEmpty'],
            preInsert: true,
        }, {
            field: 'remark',
            title: 'T_LIMS_OUTSOURCE_APPLY.REMARK',
            preInsert: true,
        }]
    },

    getAuditListColumns: function () {
        return [{
            checkbox: true
        },{
            index: true
        }, this.getBpmnColumn(limsOutsourceApply.workflow.dbTable), {
            field: 'applyCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.APPLYCODE',
            type: 'link',
            width: 140
        }, {
            field: 'outsourcerName',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERNAME',
            // width: 140
        }, {
            field: 'outsourcerCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERCODE',
            width: 140
        }, {
            field: 'courierNumber',
            title: 'T_LIMS_OUTSOURCE_APPLY.COURIERNUMBER',
            width: 140
        }, {
            field: 'courier',
            title: 'T_LIMS_OUTSOURCE_APPLY.COURIER',
            type: 'select',
            firstBlank: false,
            search: true,
            category: 'sys',
            param: {
                codeCategoryId: 'courier'
            },
            width: 140
        }, {
            field: 'remark',
            title: 'T_LIMS_OUTSOURCE_APPLY.REMARK',
            width: 200
        }, {
            field: 'createdByName',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDBYNAME',
            width: 140
        }, {
            field: 'createdTime',
            type: 'dateTime',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDTIME',
            width: 150
        }]
    },

    getResultListColumns: function () {
        return [{
            checkbox: true
        },{
            index: true
        }, this.getBpmnColumn(limsOutsourceApply.workflow.dbTable), {
            field: 'applyCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.APPLYCODE',
            type: 'link',
            width: 140
        }, {
            field: 'outsourcerName',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERNAME',
            // width: 140
        }, {
            field: 'outsourcerCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERCODE',
            width: 140
        }, {
            field: 'courierNumber',
            title: 'T_LIMS_OUTSOURCE_APPLY.COURIERNUMBER',
            width: 140
        }, {
            field: 'courier',
            title: 'T_LIMS_OUTSOURCE_APPLY.COURIER',
            type: 'select',
            firstBlank: false,
            search: true,
            category: 'sys',
            param: {
                codeCategoryId: 'courier'
            },
            width: 140
        }, {
            field: 'remark',
            title: 'T_LIMS_OUTSOURCE_APPLY.REMARK',
            width: 200
        }, {
            field: 'createdByName',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDBYNAME',
            width: 140
        }, {
            field: 'createdTime',
            type: 'dateTime',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDTIME',
            width: 150
        }]
    },

    getSearchListColumns: function () {
        return [{
            checkbox: true
        },{
            index: true
        }, this.getBpmnColumn(limsOutsourceApply.workflow.dbTable), {
            field: 'applyCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.APPLYCODE',
            type: 'link',
            width: 140
        }, {
            field: 'outsourcerName',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERNAME',
            // width: 140
        }, {
            field: 'outsourcerCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERCODE',
            width: 140
        }, {
            field: 'courierNumber',
            title: 'T_LIMS_OUTSOURCE_APPLY.COURIERNUMBER',
            width: 140
        }, {
            field: 'courier',
            title: 'T_LIMS_OUTSOURCE_APPLY.COURIER',
            type: 'select',
            firstBlank: false,
            search: true,
            category: 'sys',
            param: {
                codeCategoryId: 'courier'
            },
            width: 140
        }, {
            field: 'remark',
            title: 'T_LIMS_OUTSOURCE_APPLY.REMARK',
            width: 200
        }, {
            field: 'createdByName',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDBYNAME',
            width: 140
        }, {
            field: 'createdTime',
            type: 'dateTime',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDTIME',
            width: 150
        }]
    },

    getChooseListColumns: function () {
        return [{index: true},{
            field: 'applyCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.APPLYCODE',
            width: 140
        }, {
            field: 'outsourcerName',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERNAME',
            // width: 140
        }, {
            field: 'outsourcerCode',
            title: 'T_LIMS_OUTSOURCE_APPLY.OUTSOURCERCODE',
            width: 140
        }, {
            field: 'courierNumber',
            title: 'T_LIMS_OUTSOURCE_APPLY.COURIERNUMBER',
            width: 140
        }, {
            field: 'courier',
            title: 'T_LIMS_OUTSOURCE_APPLY.COURIER',
            type: 'select',
            firstBlank: false,
            search: true,
            category: 'sys',
            param: {
                codeCategoryId: 'courier'
            },
            width: 140
        }, {
            field: 'remark',
            title: 'T_LIMS_OUTSOURCE_APPLY.REMARK',
            width: 200
        }, {
            field: 'createdByName',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDBYNAME',
            width: 140
        }, {
            field: 'createdTime',
            type: 'dateTime',
            title: 'T_LIMS_OUTSOURCE_APPLY.CREATEDTIME',
            width: 150
        }]
    },

    baseUrl: IFM_CONTEXT + '/secure/basemodule/business/outsource-applys',

    workflow: {
        dbTable: 'T_LIMS_OUTSOURCE_APPLY',
        columns: [{
            field: 'id',
            title: 'T_LIMS_OUTSOURCE_APPLY.ID'
        }]
    },

    /**
     * 以下为外包单样本表结构
     */
    getSampleEditListColumns: function (showResult, resultEdit) {
        var baseColumn = [{
            checkbox: true
        },{
            index: true
        }, {
            field: 'sampleCode',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.SAMPLECODE',
            width: 140
        }, {
            field: 'ext$.sampletype',
            title: 'T_LIMS_SAMPLE.SAMPLETYPE',
            width: 140
        }, {
            field: 'batchCode',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.BATCHCODE',
            width: 140
        }, {
            field: 'productCode',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.PRODUCTCODE',
            width: 140
        }, {
            field: 'productName',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.PRODUCTNAME',
            width: 140
        },]
        var resultColumn = [{
            field: 'testResult',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.TESTRESULT',
            editor: resultEdit,
            width: 140
        },]
        if (showResult) {
            baseColumn = baseColumn.concat(resultColumn)
        }
        return baseColumn
    },

    getSampleBaseInfoFormFields: function (applyId, outsourcerId) {
        return [{
            field: 'sampleCode',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.SAMPLECODE',
            type: 'choose',
            editor: true,
            category: 'sample-choose',
            single: true,
            cleanable: false,
            preInsert: true,
            onBeforeChoose: function () {
                return {
                    outsourcerId: outsourcerId,
                    status_IN: 'inExperiment',
                    target_filter: encodeURI(JSON.stringify({
                        type: 'unassigned',
                        targetTable: 'T_LIMS_OUTSOURCE_SAMPLE',
                        targetMatchColumn: 'BATCHSAMPLEID',
                        thisMatchColumn: 'BATCHSAMPLEID',
                        filter: [{
                            targetFilterColumn: 'applyId',
                            targetFilterValue: applyId
                        }]
                    }))
                }
            },
            onAfterChoose: function (rows) {
                if (rows && rows.length > 0) {
                    var data = {
                        sampleCode: rows[0].sampleCode,
                        batchCode: rows[0].ext$.batchcode,
                        sampleId: rows[0].id,
                        batchId: rows[0].ext$.batchid,
                        batchSampleId: rows[0].ext$.batchsampleid,
                        // 避免后台报错，这里搞个假字段装ext里面
                        productids: rows[0].ext$.productid,
                        productName: rows[0].ext$.productname,
                        productCode: rows[0].ext$.productcode
                    }
                    this.setData(data)
                    console.log(data)
                }
            },
            validators: ['notEmpty'],
        }, {
            field: 'batchCode',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.BATCHCODE',
            preInsert: true,
            editable: false,
            readonly: true,
            validators: ['strLength[0,32]', 'notEmpty']
        }, {
            field: 'productCode',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.PRODUCTCODE',
            preInsert: true,
            editable: false,
            readonly: true,
            validators: ['strLength[0,32]', 'notEmpty']
        }, {
            field: 'productName',
            title: 'T_LIMS_OUTSOURCE_SAMPLE.PRODUCTNAME',
            preInsert: true,
            editable: false,
            readonly: true,
            validators: ['strLength[0,120]', 'notEmpty']
        },]
    },

    applySampleUrl: IFM_CONTEXT + '/secure/basemodule/business/outsource-samples',

    /**
     * 以下为工作流审核记录用到的
     */
    getFlowListColumns: function () {
        return [{
            index: true
        }, {
            title: 'CORE.MODULE.SYS.T_CORE_BPMN_DIAGRAM.CANDIDATOR.TASKNAME',
            field: 'taskName',
            width: 140
        }, {
            title: 'CORE.MODULE.SYS.T_CORE_BPMN_DIAGRAM.CANDIDATOR.USER',
            field: 'auditedByName',
            width: 140
        }, {
            title: 'T_CORE_INTERNAL_AUDIT.AUDITDATE',
            field: 'auditedTime',
            width: 150
        }, {
            title: 'GIKAM.WORKFLOW.PASS.OPINION.TITLE',
            field: 'comment',
            width: 240
        }, {
            title: 'CORE.MODULE.SYS.T_CORE_BPMN_DIAGRAM.COMMENT.ROUTE',
            field: 'route',
            width: 140
        }]
    },
    getBpmnColumn : function(dbTable, pageType) {
        return {
            field : 'ext$.step',
            title : 'GIKAM.BPMN.FIELD.TITLE.STATUS',
            sort : false,
            type : 'select',
            items : this.getQuickSearchItems(pageType),
            match : Gikam.isEmpty(pageType) ? 'SB' : 'SEQ',
            width : 100,
            formatter : function (index, value, row, text) {
                var taskName = Gikam.getFieldValue(row, 'ext$.taskname_');
                var psStatus = Gikam.status.getRowProcessStatus(row);
                if (typeof psStatus === 'undefined') {
                    return '';
                }
                if (taskName) {
                    var color = ''
                    if (psStatus.indexOf('_rejected') > -1) {
                        color = 'red'
                    } else if (psStatus.indexOf('_undo') > -1) {
                        color = '#ffba00'
                    }
                    return '<a href="javascript:;" style="color:' + color + ';" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + taskName + '</a>';
                }
                if (Gikam.isEmpty(pageType)) {
                    if (value.indexOf('未提交') === 0) {
                        return '<a href="javascript:;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + Gikam.propI18N('GIKAM.BPMN.STATUS.RAW') + '</a>';
                    } else if (value.indexOf('待审核') === 0 || value.indexOf('结果录入')=== 0) {
                        return '<a href="javascript:;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + value + '</a>';
                    } else if (value.indexOf('完成') === 0) {
                        return '<a href="javascript:;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + Gikam.propI18N('GIKAM.BPMN.STATUS.DONE') + '</a>';
                    }
                } else {
                    if (psStatus.indexOf('draft') === 0) {
                        if (psStatus === 'draft_rejected') {
                            return '<a href="javascript:;" style="color:red;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + Gikam.propI18N('GIKAM.BPMN.STATUS.REJECT')
                                + '</a>';
                        } else if (psStatus === 'draft_undo') {
                            return '<a href="javascript:;" style="color:#ffba00;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">'
                                + Gikam.propI18N('GIKAM.BPMN.STATUS.UNDO') + '</a>';
                        } else {
                            return '<a href="javascript:;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + Gikam.propI18N('GIKAM.BPMN.STATUS.RAW') + '</a>';
                        }
                    } else if (psStatus.indexOf('approve') === 0) {
                        if (psStatus === 'approve_rejected') {
                            return '<a href="javascript:;" style="color:red;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + Gikam.propI18N('GIKAM.BPMN.STATUS.REJECT')
                                + '</a>';
                        } else {
                            return '<a href="javascript:;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + Gikam.propI18N('GIKAM.BPMN.STATUS.APPROVE') + '</a>';
                        }
                    } else if (psStatus.indexOf('done') === 0) {
                        return '<a href="javascript:;" onclick="Gikam.bpmn.openProcessStatus(\'' + dbTable + '\',\'' + row.id + '\')">' + Gikam.propI18N('GIKAM.BPMN.STATUS.DONE') + '</a>';
                    }
                }

                return '';
            }
        }
    },
    getQuickSearchItems : function (pageType) {
        if (pageType === 'edit') {
            return [ {
                text : '',
                value : ''
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.RAW'),
                value : 'draft'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.REJECT'),
                value : 'draft_rejected'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.UNDO'),
                value : 'draft_undo'
            } ];
        } else if (pageType === 'audit') {
            return [ {
                text : '',
                value : ''
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.APPROVE'),
                value : 'approve'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.REJECT'),
                value : 'approve_rejected'
            } ];
        } else if (pageType === 'search') {
            return [ {
                text : '',
                value : ''
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.APPROVE'),
                value : 'approve'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.REJECT'),
                value : 'draft_rejected'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.DONE'),
                value : 'done'
            } ]
        } else if (pageType === 'all') {
            return [ {
                text : '',
                value : ''
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.RAW'),
                value : 'draft'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.APPROVE'),
                value : 'approve'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.REJECT'),
                value : 'draft_rejected'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.DONE'),
                value : 'done'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.UNDO'),
                value : 'draft_undo'
            } ]
        } else {
            return [ {
                text : '',
                value : ''
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.RAW'),
                value : '未提交'
            }, {
                text : '待审核',
                value : '待审核'
            }, {
                text : '结果录入',
                value : '结果录入'
            }, {
                text : Gikam.propI18N('GIKAM.BPMN.STATUS.DONE'),
                value : '完成'
            } ]
        }
    },
})

